//
//  SdScrollView.m
//  GC_OC
//
//  Created by lbh on 2022/4/5.
//

#import "SdScrollView.h"

@implementation SdScrollView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self makeUI];
    }
    return self;
}
#pragma mark --Priavte
- (void)makeUI{
    [self addSubview:self.sdCycleView];
    [self.sdCycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(wid(20));
        make.right.mas_equalTo(-wid(20));
        make.bottom.mas_equalTo(0);
    }];
}
- (void)configData:(NSArray *)imageArray{
    self.sdDataArray = imageArray;
    NSMutableArray *imageS = [[NSMutableArray alloc]init];
    for (NSDictionary *dict in imageArray) {
        NSString *ima = dict[@"cover_image"];
        [imageS addObject:ima];
    }
    self.sdCycleView.imageURLStringsGroup = imageS;
   
}
#pragma mark --SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    NSDictionary *dict = self.sdDataArray[index];
    if ([dict isKindOfClass:[NSDictionary class]]) {
        NSString *link = dict[@"link"];
        if (![NSString isEmpty:link]) {
            [NSString applicationOpenUrl:link];
        }
    }
}
#pragma mark --Lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}
- (SDCycleScrollView *)sdCycleView {
    
    if (!_sdCycleView) {
        
        _sdCycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@""]];
        _sdCycleView.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0];
        _sdCycleView.userInteractionEnabled = YES;
        _sdCycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        //轮播字体设置
        _sdCycleView.showPageControl = YES;
        _sdCycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
//        _sdCycleView.pageControlDotSize = CGSizeMake(8, 4);
        _sdCycleView.currentPageDotColor = UIColor.whiteColor;
        _sdCycleView.pageDotColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
        _sdCycleView.layer.masksToBounds = YES;
        _sdCycleView.layer.cornerRadius = 5;
        _sdCycleView.autoScrollTimeInterval = 4;
    }
    return _sdCycleView;
}
@end
